<style scoped>
.head{padding: 7px;--border-color: rgba(255,255,255,.8);}
.head-box{background: var(--color-primary);color: #fff;border-radius: 12px;padding: 10px;}
.can_withdraw{font-size: 16px;height: 80px;padding: 4px;}
.can_withdraw .flex{justify-content: space-between;}
.can_withdraw b{font-size: 24px;}
.can_withdraw .button{background: rgba(255,255,255,.2);border-radius: 16px;line-height: 32px;padding: 0 18px;}
.count_row{border-top: 1px solid var(--border-color);padding: 18px 4px;}
.count_row>.row{border-left: 1px solid var(--border-color);text-align: center;}
.count_row>.row:first-child{border-left: none;}

.menu{margin-top: 10px;}
</style>
<template>
  <div class="head">
    <div class="head-box">
      <div class="can_withdraw">
        <p>可提现（元）</p>
        <div class="flex">
          <b>{{count_data.can_withdraw}}</b>
          <p class="button" @click="to('/user/withdraw')">去提现</p>
        </div>
      </div>
      <div class="count_row flex">
        <div class="row max">
          <p>{{count_data.kickback_all}}</p>
          <p>总佣金</p>
        </div>
        <div class="row max">
          <p>{{count_data.kickback_0}}</p>
          <p>待入账</p>
        </div>
        <div class="row max">
          <p>{{count_data.kickback_1}}</p>
          <p>已入账</p>
        </div>
      </div>
      <div class="count_row flex">
        <div class="row max">
          <p>{{count_data.kickback_frozen}}</p>
          <p>冻结佣金</p>
        </div>
        <div class="row max">
          <p>{{count_data.sum_withdraw_0}}</p>
          <p>提现中</p>
        </div>
        <div class="row max">
          <p>{{count_data.sum_withdraw_1}}</p>
          <p>已提现</p>
        </div>
      </div>
    </div>
  </div>

  <van-cell-group inset class="menu">
    <van-cell title="用户等级" is-link to="/user/level" />
    <van-cell title="我的团队" is-link to="/team/children_list" />
    <van-cell title="佣金明细" is-link to="/team/kickback_list" />
    <van-cell title="提现明细" is-link to="/user/withdraw_list" />
  </van-cell-group>

  <van-empty>敬请期待</van-empty>
</template>

<script>
import {ajax} from "@/js/api_tool.js";
import s94Mjs from "s94-js";
import {href_handle} from "@/vue_plugin/router_auto.js";
import {use_config_map} from "@/store/config_map.js";

export default {
  data(){
    return {
      count_data: {
        kickback_all: 0,
        kickback_0: 0,
        kickback_1: 0,
        kickback_frozen: 0,
        sum_withdraw_0: 0,
        sum_withdraw_1: 0,
        can_withdraw: 0,
      }
    }
  },
  methods:{
    to(href){ return href_handle(href);},
  },
  computed:{},
  mounted(){
    let frozen_min_date = Date.now() -  (use_config_map().config.user.withdraw.withdraw_timeout || 0)*1000;
    frozen_min_date = s94Mjs.date('Y-M-D H:I:S', frozen_min_date);
    let where_map = {
      kickback_all: {type:'sumKickback'},
      kickback_0: {type:'sumKickback_0'},
      kickback_1: {type:'sumKickback_1'},
      kickback_frozen: {type:'sumKickback_1', where:{confirm_time:{gt:frozen_min_date}}},
      sum_withdraw_0: {type:'sumWithdraw_0'},
      sum_withdraw_1: {type:'sumWithdraw_1'},
      can_withdraw: {type:'canWithdraw'},
    }
    ajax({url:'/home/team/count_data', data:{where_map:where_map}, method:'POST'}, (res)=>{
      this.count_data = res.data;
    })
  }
}
</script>